package org.open.otalk.api.r1.listener;

import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.open.otalk.api.r1.OTalkClient;
import org.open.otalk.api.r1.packet.PingExtension;

public class PingListener implements PacketListener {
	
	private OTalkClient mClient;
	public PingListener(OTalkClient client) {
		mClient = client;
	}

	@Override
	public void processPacket(Packet packet) {
		 if (!(packet instanceof PingExtension))
				return;
			    PingExtension p = (PingExtension) packet;
			    if (p.getType() == IQ.Type.GET) {
				PingExtension pong = new PingExtension();
				pong.setType(IQ.Type.RESULT);
				pong.setTo(p.getFrom());
				pong.setPacketID(p.getPacketID());
				mClient.sendPacket(packet);
			    }
	}

}
